@extends('shared.adminBase')
@section('title','编辑活动')
@section('styles')
    <link href="/lightbox/css/lightbox.min.css" rel="stylesheet"/>
@endsection
@section('content')
    <section class="content-header">
        <h1>编辑活动</h1>
        <ol class="breadcrumb">
            <li><a href="{{URL::action('AdminController@innerIndex')}}"><i class="fa fa-dashboard"></i> 首页</a>
            </li>
            <li><a href="{{URL::action('GameController@getActivityList')}}">活动记录</a></li>
            <li class="active">编辑活动</li>
        </ol>
    </section>
    <section class="content">
        <div class="row">
            <div class="col-xs-12">
                <!-- /.box -->
                <div class="box">
                    <!-- /.box-header -->
                    <div class="box-body col-md-12">
                        <form id="form1" action="{{URL::action('GameController@updateActivity')}}"
                              method="post" enctype="multipart/form-data">
                            {{csrf_field()}}
                            <input type="hidden" name="content" value="{{$activity->content}}">
                            <input type="hidden" name="rule" value="{{$activity->rule}}">
                            <input type="hidden" name="id" value="{{$activity->activity_id}}">
                            <div class="form-group">
                                <label>活动名称<span style="color:red;">&nbsp;*</span></label>
                                <input type="text" name="name" class="form-control" style="width:50%;"
                                       placeholder="请填写活动名称" value="{{$activity->name}}">
                                @if($errors->has('name'))
                                    <span class="help-block">
                                         <strong class="text-danger">{{$errors->first('name')}}</strong>
                                    </span>
                                @endif
                            </div>
                            <div class="form-group">
                                <label>连接地址</label>
                                <input type="text" name="targetLink" class="form-control" style="width:50%;"
                                       placeholder="请填写连接地址" value="{{$activity->target_link}}">
                                @if($errors->has('targetLink'))
                                    <span class="help-block">
                                         <strong class="text-danger">{{$errors->first('targetLink')}}</strong>
                                    </span>
                                @endif
                            </div>
                            <div class="form-group">
                                <label>活动图片</label>
                                <input type="file" name="photo" id="photo">
                                <p class="help-block">图片格式不能超过2M，仅支持jpg、jpeg、gif、png格式</p>
                                @if(!empty($activity->image_path))
                                    <a class="example-image-link" href="{{ $activity->image_path }}"
                                       data-lightbox="example-1"><img src="{{$activity->image_path}}"
                                                                      alt="活动图片" title="点击放大"
                                                                      style="width:300px;height: 200px;"></a>
                                @endif
                                @if($errors->has('photo'))
                                    <span class="help-block">
                                         <strong class="text-danger">{{$errors->first('photo')}}</strong>
                                    </span>
                                @endif
                            </div>
                            <div class="form-group">
                                <label>活动简介</label>
                                <textarea class="form-control" style="width:50%;" name="intro" rows="3"
                                          placeholder="请填写活动简介">{{$activity->intro}}</textarea>
                                @if($errors->has('intro'))
                                    <span class="help-block">
                                         <strong class="text-danger">{{$errors->first('intro')}}</strong>
                                    </span>
                                @endif
                            </div>
                            <div class="form-group">
                                <div class="row">
                                    <div class="col-lg-6">
                                        <label>发布日期</label>
                                        <input type="text" style="width:50%;" name="publishDate"
                                               value="{{date('Y/m/d',strtotime($activity->publish_date))}}"
                                               class="form-control" id="startDate">
                                        @if($errors->has('publishDate'))
                                            <span class="help-block">
                                                 <strong class="text-danger">{{$errors->first('publishDate')}}</strong>
                                            </span>
                                        @endif
                                        <div class="bootstrap-timepicker">
                                            <label>发布时间</label>
                                            <input type="text" style="width:50%;" name="publishTime"
                                                   class="form-control"
                                                   id="startTime"
                                                   value="{{date('H:i',strtotime($activity->publish_date))}}">
                                            @if($errors->has('publishTime'))
                                                <span class="help-block">
                                                    <strong class="text-danger">{{$errors->first('publishTime')}}</strong>
                                                </span>
                                            @endif
                                        </div>
                                    </div>
                                    <!-- /input-group -->
                                </div>
                                <!-- /.col-lg-6 -->
                            </div>
                            <div class="form-group">
                                <div class="row">
                                    <div class="col-lg-6">
                                        <label>结束日期</label>
                                        <input type="text" style="width:50%;" name="finishDate"
                                               value="{{date('Y/m/d',strtotime($activity->finish_date))}}"
                                               class="form-control" id="endDate">
                                        @if($errors->has('finishDate'))
                                            <span class="help-block">
                                                    <strong class="text-danger">{{$errors->first('finishDate')}}</strong>
                                                </span>
                                        @endif
                                        <div class="bootstrap-timepicker">
                                            <label>结束时间</label>
                                            <input type="text" style="width:50%;" name="finishTime" class="form-control"
                                                   id="endTime"
                                                   value="{{date('H:i',strtotime($activity->finish_date))}}">
                                            @if($errors->has('finishTime'))
                                                <span class="help-block">
                                                    <strong class="text-danger">{{$errors->first('finishTime')}}</strong>
                                                </span>
                                            @endif
                                        </div>
                                    </div>
                                    <!-- /input-group -->
                                </div>
                                <!-- /.col-lg-6 -->
                            </div>
                            <div class="form-group">
                                <label>活动状态</label>
                                <div class="radio">
                                    <label>
                                        <input type="radio" name="status"
                                               value="{{App\Framework\Enum\ActivityStatusEnum::PUBLISHED}}"
                                                {{$activity->status==App\Framework\Enum\ActivityStatusEnum::PUBLISHED?'checked="checked"':''}}>
                                        {{App\Framework\Enum\ActivityStatusEnum::getName(App\Framework\Enum\ActivityStatusEnum::PUBLISHED)}}
                                    </label>
                                    <label>
                                        <input type="radio" name="status"
                                               value="{{App\Framework\Enum\ActivityStatusEnum::WAIT_PUBLISH}}" {{$activity->status==App\Framework\Enum\ActivityStatusEnum::WAIT_PUBLISH?'checked="checked"':''}}>
                                        {{App\Framework\Enum\ActivityStatusEnum::getName(App\Framework\Enum\ActivityStatusEnum::WAIT_PUBLISH)}}
                                    </label>
                                </div>
                                @if($errors->has('status'))
                                    <span class="help-block">
                                         <strong class="text-danger">{{$errors->first('status')}}</strong>
                                    </span>
                                @endif
                            </div>
                            <div class="form-group" id="ruleEditor">
                                <label>活动规则</label>
                                @if($errors->has('rule'))
                                    <span class="help-block">
                                         <strong class="text-danger">{{$errors->first('rule')}}</strong>
                                    </span>
                                @endif
                            </div>
                            <div class="form-group" id="editor">
                                <label>活动内容<span style="color:red;">&nbsp;*</span></label>
                                @if($errors->has('content'))
                                    <span class="help-block">
                                         <strong class="text-danger">{{$errors->first('content')}}</strong>
                                    </span>
                                @endif
                            </div>
                            <div class="form-group">
                                <button type="button" onclick="subForm();" class="btn btn-default">提交</button>
                                <button type="button" onclick="history.back();" class="btn btn-default">返回</button>
                            </div>
                        </form>
                    </div>
                    <!-- /.box-body -->
                </div>
                <!-- /.box -->
            </div>
            <!-- /.col -->
        </div>
        <!-- /.row -->
    </section>

@endsection
@include('UEditor::head')
@section('scripts')
    <script type="text/javascript">

        //实例化编辑器
        //建议使用工厂方法getEditor创建和引用编辑器实例，如果在某个闭包下引用该编辑器，直接调用UE.getEditor('editor')就能拿到相关的实例
        var ue = UE.getEditor('editor', {
            initialFrameHeight: 500,
            scaleEnabled: true
        });

        ue.ready(function(){
            ue.setContent($('[name="content"]').val());
            //因为Laravel有防csrf防伪造攻击的处理所以加上此行
            ue.execCommand('serverparam','_token','{{ csrf_token() }}');
        });

        var ruleUe = UE.getEditor('ruleEditor', {
            initialFrameHeight: 500,
            scaleEnabled: true
        });
        ruleUe.ready(function(){
            ruleUe.setContent($('[name="rule"]').val());
            //因为Laravel有防csrf防伪造攻击的处理所以加上此行
            ruleUe.execCommand('serverparam','_token','{{ csrf_token() }}');
        });

        function subForm() {
            $('[name="content"]').val(ue.getContent());
            $('[name="rule"]').val(ruleUe.getContent());
            $('#form1').submit();
        }
    </script>
@endsection